package com.ascentive.finallyfast.deepclean;

import java.sql.Date;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;

import com.ascentive.finallyfast.R;
import com.ascentive.finallyfast.quickboost.QuickBoostPage;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.Environment;
import android.os.StatFs;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

public class Utility {
	
	  public static long getDateBeforeNDays(long lDay)
	    {
	    	long yourDateMillis = System.currentTimeMillis() - (lDay * 24 * 60 * 60 * 1000);
	    	// Time yourDate = new Time();
	    	// yourDate.set(yourDateMillis);
	    	// String formattedDate = yourDate.format("%Y-%m-%d %H:%M:%S");
	    
	    	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
	    	String dateString = formatter.format(new Date(yourDateMillis)); // * 1000L));
	    	
	    	//textView = (TextView)findViewById(R.id.TextView01);
	    	//textView.setText(dateString);
	    	System.out.println("Past Date");
	    	System.out.println(dateString);
	    	
	    	return (yourDateMillis);
	    }
	    public static long getDateBeforeNWeeks(long lWeek)
	    {	
	    	long yourDateMillis = System.currentTimeMillis() - ( (7 * lWeek) * 24 * 60 * 60 * 1000);
	    	// Time yourDate = new Time();
	    	// yourDate.set(yourDateMillis);
	    	// String formattedDate = yourDate.format("%Y-%m-%d %H:%M:%S");
	    	
	    	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
	    	String dateString = formatter.format(new Date(yourDateMillis)); // * 1000L));
	    	
	    	//textView = (TextView)findViewById(R.id.TextView01);
	    	//textView.setText(dateString);
	    	System.out.println("Past Date");
	    	System.out.println(dateString);
	    	
	    	return (yourDateMillis);
	    }
	    public static long getDateBeforeNMonths(long lMonth)
	    {
	    	long yourDateMillis = System.currentTimeMillis() - ((30 * lMonth) * 24 * 60 * 60 * 1000);
	    	// Time yourDate = new Time();
	    	// yourDate.set(yourDateMillis);
	    	// String formattedDate = yourDate.format("%Y-%m-%d %H:%M:%S");
	    	
	    	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
	    	String dateString = formatter.format(new Date(yourDateMillis)); // * 1000L));
	    	
	    	//textView = (TextView)findViewById(R.id.TextView01);
	    	//textView.setText(dateString);
	    	System.out.println("Past Date");
	    	System.out.println(dateString);
	    	
	    	return (yourDateMillis);
	    }
	    
	    public static String convertToStringDateFromDouble(long dd)
	    {
	    	SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
	    	String dateString = formatter.format(new Date(dd)); // * 1000L));
	    	
	    	return dateString;
	    }
	    
	 // Return Size of SD card
		public static long getSDCardMemory() {
			
			StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
			long bytesAvailable = (long) stat.getBlockSize()
					* (long) stat.getBlockCount();
			long megAvailable = bytesAvailable / 1048576;
			System.out.println("Megs :" + megAvailable);
			
			return megAvailable;
		}
		
		public static String megabytesAvailable() {
			NumberFormat numberFormat = DecimalFormat.getInstance(); 
		    numberFormat.setMaximumFractionDigits(2);
		    
		    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
		    long bytesAvailable = (long)stat.getBlockSize() * (long)stat.getAvailableBlocks();
		    String formattedText = numberFormat.format(bytesAvailable / (1024.f * 1024.f));
		    
		    return formattedText;
		}
		
		public static String megabytesTotal() {
			NumberFormat numberFormat = DecimalFormat.getInstance(); 
		    numberFormat.setMaximumFractionDigits(2);
		    
		    StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
		    long bytesTotal = (long)stat.getBlockSize() * (long)stat.getBlockCount();
		    String formattedText = numberFormat.format(bytesTotal / (1024.f * 1024.f));
		    
			return formattedText;
		}
		public static void DisplayToast(final DeepCleanPage ctx, String message) {
			Toast msg = Toast.makeText(ctx, message, Toast.LENGTH_LONG);
			msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2,
					msg.getYOffset() / 2);

			msg.show();
		}
		
}
